import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:tot_android_flutter/base/BasePage.dart';
import 'package:tot_android_flutter/pages/tabpage/project/child/projcet_list_controller.dart';
import 'package:tot_android_flutter/utils/utils_ext.dart';
import '../../../base/keep_alive_wrapper.dart';
import 'ProjectController.dart';
import 'child/project_list_page.dart';

class ProjectPage extends BasePage<ProjectController> {
  @override
  AppBar? buildAppBar() {
    if (controller.viewState.value.isSuccess()) {
      return AppBar(
          toolbarHeight: 0.w,
          bottom: PreferredSize(
            preferredSize: Size(double.infinity, 50.w),
            child: TabBar(
              isScrollable: true,
              tabs: controller.projectCategorys.map((e) {
                return Container(
                  height: 45.w,
                  alignment: Alignment.center,
                  child: Text(
                    e.name,
                    textAlign: TextAlign.center,
                  ),
                );
              }).toList(),
              controller: controller.tabController,
            ),
          ));
    } else {
      return null;
    }
  }

  @override
  Widget buildBody(BuildContext context) {
    // return Text("test");
    return TabBarView(
        controller: controller.tabController,
        children: controller.projectCategorys.map((e) {
          Get.lazyPut(() => ProjectListController(),
              tag: "ProjectListController-${e.id}");
          return KeepAliveWrapper(child: ProjectListPage(e.id));
        }).toList());
  }
}
